package com.hanbang.gycatering.homepage;

import com.hanbang.gangyu.R;
import com.hanbang.gycatering.application.ActivityManager;
import com.hanbang.gycatering.utils.MySharedPreferences;
import com.hanbang.gycatering.utils.MyToast;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainBaseActivity extends BaseActivity {
	private long exitTime = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onBackPressed() {
		isExitApplication(this);
	}

	public void isExitApplication(Context context) {
		if ((System.currentTimeMillis() - exitTime) > 2000) {
			MyToast.show(this, "再按一次退出程序", Toast.LENGTH_SHORT);
			exitTime = System.currentTimeMillis();
		} else {
			// 退出
			ActivityManager.getInstance().exitAllActivity();
		}
	}

	public void setGouwucheNumber(TextView textView) {
		if (isLogin(false)) {
			int num = MySharedPreferences.getSharedPreferencesKeyAndValue(this,
					MySharedPreferences.USER_DATA, "gouwucheNumber", -1);
			if (num <= 0) {
				textView.setVisibility(View.GONE);
			} else {
				textView.setVisibility(View.VISIBLE);
				textView.setText(String.valueOf(num));
			}
		} else {
			textView.setVisibility(View.GONE);
		}

	}

	@Override
	protected void onResume() {
		super.onResume();
		setGouwucheNumber((TextView) findViewById(R.id.gwc_number));
	}
}
